﻿Public Class DxOperaciones

    Public Shared Function rptGerenciales_xOperacion(ByVal descEmpresa As String, ByVal rptGerencial As EproformaCabecera) As List(Of ExOperaciones)
        Dim xOperaciones As List(Of ExOperaciones) = Nothing

        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings(descEmpresa).ConnectionString)
            Using cmd As New SqlCommand("usp_rptGerencial_xOperacion", cn)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.Add("@idProyecto", SqlDbType.Int).Value = rptGerencial.idProyecto
                cmd.Parameters.Add("@idEtapa", SqlDbType.Int).Value = rptGerencial.idEtapa
                cmd.Parameters.Add("@FechaInicial", SqlDbType.Char, 10).Value = rptGerencial.fchInicio
                cmd.Parameters.Add("@FechaFinal", SqlDbType.Char, 10).Value = rptGerencial.fchFin
                Try
                    cn.Open()
                    Using dr As SqlDataReader = cmd.ExecuteReader(CommandBehavior.SingleResult Or CommandBehavior.CloseConnection)
                        If dr.HasRows Then
                            xOperaciones = New List(Of ExOperaciones)
                            Dim xOperacion As ExOperaciones = Nothing
                            Do While dr.Read
                                xOperacion = New ExOperaciones( _
                                    dr.GetString(dr.GetOrdinal("items")), _
                                    dr.GetDecimal(dr.GetOrdinal("proforma")), _
                                    dr.GetDecimal(dr.GetOrdinal("separacionTemp")), _
                                    dr.GetDecimal(dr.GetOrdinal("separacion")), _
                                    dr.GetDecimal(dr.GetOrdinal("venta")), _
                                    dr.GetString(dr.GetOrdinal("mes")))
                                xOperaciones.Add(xOperacion)
                            Loop
                            dr.Close()
                        End If
                    End Using
                Catch ex As Exception
                    Throw
                End Try
            End Using
        End Using

        Return xOperaciones
    End Function

End Class
